<?php

namespace App\Listeners;

use App\Events\GameFinish;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class ChangeDeviceUseTime
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  GameFinish  $event
     * @return void
     */
    public function handle(GameFinish $event)
    {
        $tmp = $event->history;

        if (!$tmp->device()->update(['last_use_time'=>$tmp->end_time])){
           Log::error("last_use_time change fail, history_id:". $tmp->id);
        }

        if ($tmp->child()->update(['last_use_time'=>$tmp->end_time])){
            Log::error("child last_use_time change fail, history_id:". $tmp->id);
        }
    }
}
